package com.codecash.exception;

import com.codecash.controller.response.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExcceptionHandler {
    private static final Logger logger = LoggerFactory.getLogger(GlobalExcceptionHandler.class);

    @ExceptionHandler(Exception.class)
    public Result exceptionHandler(Exception e){
        logger.error("Global exception caught: ", e);
        return Result.error(StringUtils.hasLength(e.getMessage())? e.getMessage() : "操作失败");
    }
}